package com.ruoyi.web.controller.community;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.community.domain.CommunityFee;
import com.ruoyi.community.service.ICommunityFeeService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 物业费用管理Controller
 *
 * @author ruoyi
 * @date 2023-10-18
 */
@RestController
@RequestMapping("/community/fee")
public class CommunityFeeController extends BaseController
{
    @Autowired
    private ICommunityFeeService communityFeeService;

    /**
     * 查询物业费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('community:fee:list')")
    @GetMapping("/list")
    public TableDataInfo list(CommunityFee communityFee)
    {
        startPage();
        List<CommunityFee> list = communityFeeService.selectCommunityFeeList(communityFee);
        return getDataTable(list);
    }

    /**
     * 查询物业费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('community:fee:amount')")
    @GetMapping("/amount")
    public AjaxResult amount() {
        return success(communityFeeService.selectCommunityFeeTotalAmount());
    }

    /**
     * 导出物业费用管理列表
     */
    @PreAuthorize("@ss.hasPermi('community:fee:export')")
    @Log(title = "物业费用管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CommunityFee communityFee)
    {
        List<CommunityFee> list = communityFeeService.selectCommunityFeeList(communityFee);
        ExcelUtil<CommunityFee> util = new ExcelUtil<CommunityFee>(CommunityFee.class);
        util.exportExcel(response, list, "物业费用管理数据");
    }

    /**
     * 获取物业费用管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('community:fee:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(communityFeeService.selectCommunityFeeById(id));
    }

    /**
     * 新增物业费用管理
     */
    @PreAuthorize("@ss.hasPermi('community:fee:add')")
    @Log(title = "物业费用管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CommunityFee communityFee)
    {
        return toAjax(communityFeeService.insertCommunityFee(communityFee));
    }

    /**
     * 修改物业费用管理
     */
    @PreAuthorize("@ss.hasPermi('community:fee:edit')")
    @Log(title = "物业费用管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CommunityFee communityFee)
    {
        return toAjax(communityFeeService.updateCommunityFee(communityFee));
    }

    /**
     * 删除物业费用管理
     */
    @PreAuthorize("@ss.hasPermi('community:fee:remove')")
    @Log(title = "物业费用管理", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(communityFeeService.deleteCommunityFeeByIds(ids));
    }
}
